package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class mysqlUtil {
	private static String jdbcDriver = "jdbc:mysql://220.70.0.16:3306/carpool?useUnicode=true&characterEncoding=euckr";
	private static String dbUser = "jsp";
	private static String dbPass = "jsp";

	public static Connection getConn(){
		try {
			Connection conn = DriverManager.getConnection(jdbcDriver, dbUser, dbPass);
			Statement stmt = conn.createStatement();
			stmt.execute("SET CHARACTER SET euckr");
			stmt.execute("set names euckr");
			return conn;
//			return DriverManager.getConnection(jdbcDriver, dbUser, dbPass);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static void close(ResultSet rs) {
		if (rs != null) {
			try {
				rs.close();
			} catch (SQLException ex) {
			}
		}
	}

	public static void close(Statement stmt) {
		if (stmt != null) {
			try {
				stmt.close();
			} catch (SQLException ex) {
			}
		}
	}

	public static void close(Connection conn) {
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException ex) {
			}
		}
	}

	public static void rollback(Connection conn) {
		if (conn != null) {
			try {
				conn.rollback();
			} catch (SQLException ex) {
			}
		}
	}
}